﻿using System;
using DirectoryServicesProtocolsExtensions.LdapConnection;
using DirectoryServicesProtocolsExtensions.MetaData;
using DirectoryServicesProtocolsExtensions.SearchRequest;

namespace IntegrationTests
{
    enum DirectoryTypeTest
    {
        ActiveDirectory,
        EDirectory
    }

    public class DirectoryTest
    {
        //private readonly DirectoryTypeTest DirectoryTypeTest = DirectoryTypeTest.EDirectory;
        private readonly DirectoryTypeTest DirectoryTypeTest = DirectoryTypeTest.ActiveDirectory;
        private readonly ILdapMetaDataPropertiesContainer ldapMetaDataPropertiesContainer = new MockMetaDataPropertiesContainer();
        
        protected ILdapConnectionPropertiesContainer LdapConnectionPropertiesContainer;
        protected ILdapSearchRequestPropertiesContainer LdapSearchRequestPropertiesContainer;
        protected LdapConnectionFactory LdapConnectionFactory;
        protected LdapMetaMapFactory LdapMetaMapFactory;

        public void TestInitialize()
        {
            switch (DirectoryTypeTest)
            {
                case DirectoryTypeTest.ActiveDirectory:
                    LdapConnectionPropertiesContainer = new MockFabrikamActiveDirectoryConnectionPropertiesContainer();
                    LdapSearchRequestPropertiesContainer = new MockFabrikamActiveDirectoryQueryPropertiesContainer();
                    break;
                case DirectoryTypeTest.EDirectory:
                    LdapConnectionPropertiesContainer = new MockEDirectoryConnectionPropertiesContainer();
                    LdapSearchRequestPropertiesContainer = new MockEdirectoryQueryPropertiesContainer();
                    break;
                default:
                    throw new Exception("Unknow Connectivity test type");
            } 

            LdapConnectionFactory = new LdapConnectionFactory(LdapConnectionPropertiesContainer);
            LdapMetaMapFactory = new LdapMetaMapFactory(
                new LdapMetaMapFactoryInitializationValues(
                    ldapMetaDataPropertiesContainer.GuidEncodedAttributeBinaryAttributes,
                    ldapMetaDataPropertiesContainer.SidEncodedAttributeBinaryAttributes,
                    ldapMetaDataPropertiesContainer.Int64EncodedAttributeDateTimeAttributes,
                    ldapMetaDataPropertiesContainer.StringEncodedIntAttributes,
                    ldapMetaDataPropertiesContainer.AttributesWhichMayRequireExpansion));
        }
    }
}
